package com.qdu.servlet;

import com.qdu.entity.Management;
import com.qdu.service.impl.ManagementServiceImpl;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *修改管理员密码的servlet
 * @author Lenovo
 */
@WebServlet("/mmps")
public class modifyManagerPwdServlet extends HttpServlet{

    ManagementServiceImpl managementserviceimpl=new ManagementServiceImpl();
    
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String name=req.getParameter("name");
        String oldpwd=req.getParameter("oldpwd");
        String newpwd=req.getParameter("newpwd");
        String ensurepwd=req.getParameter("ensurepwd");
        
        Management man=managementserviceimpl.getOneManagementByName(name);//获取管理员信息
        resp.setContentType("text/html;charset=utf-8");
        if(man.getPassword().equals(oldpwd))//如果原密码正确
        {
            if(newpwd.equals(ensurepwd))//并且新密码和确认密码相同
            {
                int rows=managementserviceimpl.UpdatePassword(name, newpwd);
                resp.sendRedirect("modifyManagerPwdSuccess.jsp");
            }
            else{
                resp.sendRedirect("modifyManagerPwdDiff.jsp");
            }
        }else{
            resp.sendRedirect("modifyManagerPwdWrong.jsp");
        }
    }
    
    
}
